/**
 * Created by DukeCrushIt on 2015/7/9.
 */
//module game{
    class ButtonIconMgr{
        private buttons:eui.Component[];
        public curStateBtns:any[]=[];
        public constructor(){
            //super();
            this.buttons = [];
        }

        public addButtonIcon(button:any,center:boolean=true){
            if( this.buttons.indexOf(button) != -1) return;
            button.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.onTouchBegin, this);
            GameConst.Stage.addEventListener(egret.TouchEvent.TOUCH_END,this.onTouchEnd, this);
        }

        private onTouchBegin(evt:egret.TouchEvent){
            var button:egret.DisplayObject = evt.currentTarget;
            this.curStateBtns.push(button);
            button.y += 10;
        }

        private onTouchEnd(evt:egret.TouchEvent){
            var len = this.curStateBtns.length;
            var button:egret.DisplayObject;
            for( var idx = len - 1; idx >= 0; idx--){
                button = this.curStateBtns[idx];
                button.y -= 10;
                this.curStateBtns.splice(idx,1);
            }
        }

        private static _instance:ButtonIconMgr;
        public static getInstance():ButtonIconMgr{
            if( ButtonIconMgr._instance == null)
                ButtonIconMgr._instance = new ButtonIconMgr();
            return ButtonIconMgr._instance;
        }
    }
//}